package org.example.repository.impl;

import org.example.model.Form;
import org.example.model.FormData;
import org.example.repository.FormUseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
public class FormUseDataImpl implements FormUseData {
    @Autowired
    private MongoTemplate mongoTemplate;
    @Override
    public void saveData(FormData formData) {
        mongoTemplate.save(formData, formData.getFormName()+"Data");
    }

    @Override
    public int deleteData(Integer dataId, String formName) {
        return 0;
    }

    @Override
    public int updateData(FormData formData) {
        return 0;
    }

    @Override
    public List<FormData> findData(String formName) {
        Query query = new Query(Criteria.where("formName").is(formName));
        List<FormData> formData = mongoTemplate.find(query, FormData.class, formName+"Data");
        return  formData;
    }
}
